package bcnet.dao;

import java.util.Date;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import bcnet.domain.BoughtCodeVO;
import bcnet.domain.UserCode;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

public class BoughtCodeDao {
	
	public String addBoughtCode(String code, int numberOfStock, double buyPrice, Date buyDate){
		String result="";
		PersistenceManager pm = PMF.get().getPersistenceManager();
		
		BoughtCodeVO boughtCode;
		
		try{
			boughtCode = new BoughtCodeVO(code,numberOfStock,buyPrice,buyDate);
			pm.makePersistent(boughtCode);
		}
		catch (javax.jdo.JDOObjectNotFoundException ex){
		}
		finally{
			pm.close();
		}
		return result;
	}
	
	public List<BoughtCodeVO> getBoughtCodeList(){
		//String result[] = new String[2];
		PersistenceManager pm = PMF.get().getPersistenceManager();
		
		List<BoughtCodeVO> results; 
		Query q = pm.newQuery(BoughtCodeVO.class);
		try{
			q.setOrdering("code desc");
			//q.declareParameters("String lastNameParam");
			results = (List<BoughtCodeVO>) q.execute();
			results.size();
		}
		finally{
			 q.closeAll();
			pm.close();
		}
		return results;
	}
	

}
